﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ART.Common;

namespace ART.Admini.Users
{
    public partial class UserLangList : System.Web.UI.Page
    {

        private ART.BLL.B_UserLang bll = new ART.BLL.B_UserLang();
        protected int UId = 0;
        private string strWhere, SearchName;

        protected void Page_Load(object sender, EventArgs e)
        {
            SearchName = ART.Common.LYRequest.GetString("SearchName", true);
            UId = LYRequest.GetInt("id", 0);
            if (!IsPostBack)
            {
                if (UId == 0)
                {
                    MessageBox.JSLoad(sender, "alert('非法的用户参数!');reloadDlg(true);");
                    return;
                }
                InitData();
                BindList();
            }
        }
        private void InitData()
        {

        }
        private void BindList()
        {

            #region __________Where语句__________

            strWhere = "  uid=" + UId;
            if (SearchName != "")
            {
                //strWhere += " and LangId in (name like '%" + SearchName + "%' or jfwz like '%" + SearchName + "%' or jfIP like '%" + SearchName + "%')";
            }
            #endregion

            rpt_List.PageLink = "UserLangList.aspx?Search=Yes&SearchName=" + Utils.UrlEncode(SearchName);
            rpt_List.PageSize = 20;
            rpt_List.CurrentPage = LYRequest.GetInt("page", 1);

            DataSet ds = BLL.GetListByPage.GetDataSet_NoCache("UserLang", "*", strWhere, "", "ID DESC", "ID", rpt_List.CurrentPage, rpt_List.PageSize, 1);

            rpt_List.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            JBind.BindList(rpt_List, ds.Tables[1]);
        }
        protected void btnSearch_Click(object sender, EventArgs p1)
        {
            StringBuilder builder = new StringBuilder("UserLangList.aspx?Search=Yes");
           // builder.Append("&TypeId=" + JBind.GetSelectedList(drpTypeId));

            //if (!string.IsNullOrEmpty(this.txtSearchName.Text.Trim()))
            //{
            //    builder.Append("&SearchName=" + this.txtSearchName.Text.Trim());
            //}
            base.Response.Redirect(builder.ToString());
        }
        protected void lbtnDeletes_Click(object sender, EventArgs p1)
        {
#warning BLL.B_TBAdmin.IsPermissions(0x6c)
            if (BLL.B_TBAdmin.IsPermissions(0x6c))
            {
                //int num = 0;
                foreach (RepeaterItem item in this.rpt_List.Items)
                {
                    HtmlInputCheckBox box = (HtmlInputCheckBox)item.FindControl("cheId");
                    if (box.Checked)
                    {
                        bll.Delete(int.Parse(box.Value));
                        // num++;
                    }
                }
                base.Response.Redirect(HttpContext.Current.Request.Url.PathAndQuery);
            }
            else
            {
                MessageBox.Alert(sender, "没有删除权限!");
            }
        }
        protected void rpt_List_ItemCommand(object source, RepeaterCommandEventArgs p1)
        {
            int num = int.Parse(p1.CommandArgument.ToString());
            if (p1.CommandName == "lbtnDelete")
            {
#warning delte IsPermissions(0x6c)
                if (!BLL.B_TBAdmin.IsPermissions(0x6c))
                {
                    MessageBox.Alert(source, "没有删除权限!");
                }
                else
                {
                    bll.Delete(num);
                    base.Response.Redirect(HttpContext.Current.Request.Url.PathAndQuery);
                }
            }
        }
    }
}
